package com.cy.platform;


import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class LineAdapter extends RecyclerView.Adapter<LineAdapter.LineViewHolder> {
    private List<CYPlatformBean.LineBean> lineData = new ArrayList<>();
    private Context mContext;

    public void setNewData(List<CYPlatformBean.LineBean> lineData) {
        this.lineData.clear();
        if (lineData != null) {
            this.lineData.addAll(lineData);
        }
        notifyDataSetChanged();
    }


    @NonNull
    @Override
    public LineViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        return new LineViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_line, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull LineViewHolder holder, int position) {
        CYPlatformBean.LineBean lineBean = lineData.get(position);
        holder.llLineLayout.setBackgroundColor(ContextCompat.getColor(mContext, position % 2 == 0 ? android.R.color.transparent : R.color.color_06395f));
//        holder.ivUpAndDown.setVisibility(position == 0?View.VISIBLE:View.INVISIBLE);
        holder.ivUpAndDown.setVisibility(View.INVISIBLE);
        holder.tvLineName.setText(lineBean.getLineName());
        holder.tvDevideNum.setText(lineBean.getDevideNum());
        holder.tvShipped.setText(lineBean.getShipped());
        holder.tvHasShipped.setText(lineBean.getHasShipped());
        holder.tvGoodsNum.setText(lineBean.getGoodsNum());
        holder.tvNoGoodsNum.setText(lineBean.getNoGoodsNum());
        holder.tvScrapNum.setText(lineBean.getScrapNum());
        holder.tvGoodsRate.setText(lineBean.getGoodsRate());
        holder.tvDate.setText(lineBean.getDate());
        holder.tvTotalOutput.setText(lineBean.getTotalOutput());
    }

    @Override
    public int getItemCount() {
        return lineData.size();
    }

    public static class LineViewHolder extends RecyclerView.ViewHolder {
        private LinearLayout llLineLayout;
        private ImageView ivUpAndDown;
        private TextView tvLineName, tvDevideNum, tvShipped, tvHasShipped, tvGoodsNum, tvNoGoodsNum, tvScrapNum, tvGoodsRate, tvDate, tvTotalOutput;

        public LineViewHolder(View itemView) {
            super(itemView);
            llLineLayout = itemView.findViewById(R.id.ll_line_layout);
            ivUpAndDown = itemView.findViewById(R.id.iv_up_and_down);
            tvLineName = itemView.findViewById(R.id.tv_line_name);
            tvDevideNum = itemView.findViewById(R.id.tv_devide_num);
            tvShipped = itemView.findViewById(R.id.tv_shipped);
            tvHasShipped = itemView.findViewById(R.id.tv_has_shipped);
            tvGoodsNum = itemView.findViewById(R.id.tv_goods_num);
            tvNoGoodsNum = itemView.findViewById(R.id.tv_no_goods_num);
            tvScrapNum = itemView.findViewById(R.id.tv_scrap_num);
            tvGoodsRate = itemView.findViewById(R.id.tv_goods_rate);
            tvDate = itemView.findViewById(R.id.tv_date);
            tvTotalOutput = itemView.findViewById(R.id.tv_total_output);
        }
    }

}
